#include "stdafx.h"
#include "ui/poke_window_prop_list_ctrl.h"
#include "poke_framework.h"
#include "base/window/window_utils.h"
#include "models/atom_interface/ai_window_info_fetcher.h"

CPokeWindowPropListCtrl::CPokeWindowPropListCtrl()
{

}

CPokeWindowPropListCtrl::~CPokeWindowPropListCtrl()
{

}

BOOL CPokeWindowPropListCtrl::CanEdit(int nRow, int nCol)
{
    if(0 > nRow || 0 >= nCol) {
        return FALSE;
    }

    return TRUE;
}

BOOL CPokeWindowPropListCtrl::OnRequestEdit(int nRow, int nCol, CRect oEditRect)
{
    if(0 > nRow) {
        return FALSE;
    }

    oEditRect.top += 1;
    oEditRect.bottom += 0;

    WindowPropKey oPropKey;
    oPropKey.m_bIsAtom = GetItemText(nRow, 0) == _T("YES");
    oPropKey.m_strPropKey = GetItemText(nRow, 1);
    CString strPropValue = GetItemText(nRow, 2);
    
    WindowProps vWindowProps;
    PokeFramework::get()->Execute(PAN_WINDOW_INFO_FETCHER, PFI_GET_WINDOW_PROPS, &vWindowProps, NULL);

    m_oWindowPropFetcher.Create(WS_CHILD, oEditRect, this, 0);
    m_oWindowPropFetcher.SetFont(GetFont(), TRUE);
    m_oWindowPropFetcher.ResetOption(nCol < 2, oPropKey, strPropValue);
    m_oWindowPropFetcher.ShowWindow(SW_SHOW);
    m_oWindowPropFetcher.SetFocus();

    return TRUE;
}

BOOL CPokeWindowPropListCtrl::OnRequestDelete(int nRow)
{
    if(0 > nRow) {
        return FALSE;
    }

    WindowPropKey oPropKey;
    oPropKey.m_bIsAtom = GetItemText(nRow, 0) == _T("YES");
    oPropKey.m_strPropKey = GetItemText(nRow, 1);
    PokeFramework::get()->Execute(PAN_WINDOW_INFO_FETCHER, PFI_REMOVE_WINDOW_PROP, &oPropKey, NULL);
    PokeFramework::get()->FireEvent(PEI_UPDATE_UI, NULL);

    return FALSE;
}